package com.futao.springbootlearn20220224.aware;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceAware;
import org.springframework.stereotype.Component;

import java.util.Locale;

/**
 * 国际化
 * 必须要有默认.properties，否则读取不到，会报错
 *
 * @author futao@gmail.com
 * @date 2022/3/9
 */
@Slf4j
@Component
public class MessageSourceAwareDemo implements MessageSourceAware {
    @Override
    public void setMessageSource(MessageSource messageSource) {
        String messageEn = messageSource.getMessage("greeting", new Object[]{"李达康"}, Locale.ENGLISH);
        String messageZh = messageSource.getMessage("greeting", new Object[]{"李达康"}, Locale.CHINESE);
        log.info("获取到messageEn:{}", messageEn);
        log.info("获取到messageZh:{}", messageZh);
    }
}
